<template>
<div class="enter">
  <input type="text" v-model="addstu.stuno" placeholder="请输入学号">
  <input type="text" v-model="addstu.class" placeholder="请输入班级">
  <input type="text" v-model="addstu.name" placeholder="请输入姓名">
  <input type="text" v-model="addstu.gender" placeholder="请输入性别">
  <input type="text" v-model="addstu.age" placeholder="请输入年龄">

  <button @click="addstudent">增加</button>
</div>
</template>

<script>
import {students} from "../store/student"
export default {

  name: "Student",
  data() {
    return {
      students,
      addstu: {}
    }
  },
  methods: {
    addstudent() {
      let stu = {}
        stu.stuno  = this.addstu.stuno
        stu.class  = this.addstu.class
        stu.name   = this.addstu.name
        stu.gender = this.addstu.gender
        stu.age    = this.addstu.age
        if(stu.stuno != '' && stu.name != '') {
            this.students.push(stu);
        }else {
            alert("请输入班级和姓名")
            return;
        }
        
        this.addstu.stuno  = ''
        this.addstu.class  = ''
        this.addstu.name   = ''
        this.addstu.gender = ''
        this.addstu.age    = ''
  }
}
}
</script>

<style scoped>
</style>